"""
Classes in this file are interfaces connecting the functions from runtime-library and user code.


"""
from typing import List, Type
from .builtin_functions_interface_classes.base import PMBuiltinFunction
from .builtin_functions_interface_classes import math_function_interfaces, random_function_interfaces, \
    container_func_interfaces


class BuiltinFunctions:
    def __init__(self):
        self.funcs = {}
        self.add_functions(container_func_interfaces)
        self.add_functions(math_function_interfaces)
        self.add_functions(random_function_interfaces)

    def has_function(self, func_name):
        return func_name in self.funcs

    def add_functions(self, funcs: List[Type[PMBuiltinFunction]]):
        for func_cls in funcs:
            self.add_function(func_cls())

    def add_function(self, f: PMBuiltinFunction):
        assert isinstance(f, PMBuiltinFunction)
        assert f.name not in self.funcs
        self.funcs[f.name] = f

    def get_function(self, func_name: str) -> PMBuiltinFunction:
        return self.funcs[func_name]


builtin_functions = BuiltinFunctions()
